﻿using System;
using System.Data;
using DataAccessObject;
using EntityObject;
using SharedLibraries;
using SharedLibraries.Constants;
using ThangNM_LIB.FUNC;

namespace ThangNM
{
    public partial class Media : System.Web.UI.Page
    {
        public ThangNM.PublicInterface.Home_New mtpHome;

        #region "Properties & Event"
        public Int16 iType
        {
            get { return (Int16)ViewState["iType"]; }
            set { ViewState["iType"] = value; }
        }
        public string sType
        {
            get { return (string)ViewState["sType"]; }
            set { ViewState["sType"] = value; }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                mtpHome = Master as ThangNM.PublicInterface.Home_New;
                mtpHome.setClearMsg();
                if (!IsPostBack)
                    BindData();
            }
            catch (Exception ex)
            {
                MsgUC1.setNotifications(ConstEx.FunctionSetMsg.ERROR, ex.Message, ex.ToString());
            }
        }

        private void BindData()
        {
            Int16 id = 0;
            Int16.TryParse(StringEx.Trim(Request.QueryString[QueryString.group]).Replace("/", ""), out id);
            CategoryEO _CategoryEO = new CategoryEO();
            if (id <= 0)
                _CategoryEO = (new CategoryDAO()).SelectBy_sQueryString_sUrl(StringEx.Trim(Request.QueryString[QueryString.group]).Replace("/", ""), System.IO.Path.GetFileName(Request.Url.LocalPath));
            else
                _CategoryEO = (new CategoryDAO()).SelectItem(id);
            if (_CategoryEO == null)
                return;
            String urlSEO = _CategoryEO.sUrlRewrite;
            if (Request.QueryString[QueryString.page] != null)
            {
                Topic_List_ShowUC1.PageNumber = Convert.ToInt32(StringEx.Trim(Request.QueryString[QueryString.page]).Replace("/", ""));
                if (Topic_List_ShowUC1.PageNumber != 1)
                    urlSEO = urlSEO + ConstEx.UrlEX_C._Trang + Topic_List_ShowUC1.PageNumber;
            }
            if (!StringEx.Equals(Request.RawUrl.Substring(1), urlSEO))
            {
                Commons.setRedirect(Page, urlSEO);
                return;
            }
            Commons.setSEO_ON_PAGE(Page, _CategoryEO, this.GetType());
            DataTable dt = (new CategoryDAO()).Category_Topic(ConstEx.TableID_C.Media, StringEx.getArrayKey(_CategoryEO.FK_sTopicID));
            Topic_List_ShowUC1.setTitle(_CategoryEO.sTitle);
            if (DataTableEx.DataTable_OK(dt) == false)
            {
                return;
            }
            Topic_List_ShowUC1.sUrlNavigator = _CategoryEO.sUrlRewrite + "/";
            Topic_List_ShowUC1.BindData(dt, _CategoryEO);
        }
    }
}